﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Compute
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.text_display.AutoSize = false;
            this.text_display.Height = 100;
            init();
        }
        public void init()
        {   
            this.text_display.Text = "";
        }
        private string temp = "";

        private void btn_0_Click(object sender, EventArgs e)
        {
            temp += this.btn_0.Text.Trim();
            this.text_display.Text = temp;
        }

        private void btn_point_Click(object sender, EventArgs e)
        {
            temp += this.btn_point.Text.Trim();
            this.text_display.Text = temp;
        }

        private void btn_compute_Click(object sender, EventArgs e)
        {
         
            GetResult(this.text_display.Text.Trim());

        }
        public void GetResult(string expression)
        {
            try
            {
              object result = new DataTable().Compute(expression, "");
              temp += "="+result;
              this.text_display.Text = temp;
            }
            catch (Exception e)
            {
                MessageBox.Show("请输入正确的算式！",e.Message);
            }
            
        }
        private void btn_1_Click(object sender, EventArgs e)
        {
            temp += this.btn_1.Text.Trim();
            this.text_display.Text = temp;
        }

        private void btn_2_Click(object sender, EventArgs e)
        {
            temp += this.btn_2.Text.Trim();
            this.text_display.Text = temp;
        }

        private void btn_3_Click(object sender, EventArgs e)
        {
            temp += this.btn_3.Text.Trim();
            this.text_display.Text = temp;
        }

        private void btn_4_Click(object sender, EventArgs e)
        {
            temp += this.btn_4.Text.Trim();
            this.text_display.Text = temp;
        }

        private void btn_5_Click(object sender, EventArgs e)
        {
            temp += this.btn_5.Text.Trim();
            this.text_display.Text = temp;
        }

        private void btn_6_Click(object sender, EventArgs e)
        {
            temp += this.btn_6.Text.Trim();
            this.text_display.Text = temp;
        }

        private void btn_7_Click(object sender, EventArgs e)
        {
            temp += this.btn_7.Text.Trim();
            this.text_display.Text = temp;
        }

        private void btn_8_Click(object sender, EventArgs e)
        {
            temp += this.btn_8.Text.Trim();
            this.text_display.Text = temp;
        }

        private void btn_9_Click(object sender, EventArgs e)
        {
            temp += this.btn_9.Text.Trim();
            this.text_display.Text = temp;
        }

        private void btn_add_Click(object sender, EventArgs e)
        {
            temp += this.btn_add.Text.Trim();
            this.text_display.Text = temp;
        }

        private void btn_sub_Click(object sender, EventArgs e)
        {
            temp += this.btn_sub.Text.Trim();
            this.text_display.Text = temp;
        }

        private void btn_mul_Click(object sender, EventArgs e)
        {
            temp += this.btn_mul.Text.Trim();
            this.text_display.Text = temp;
        }

        private void btn_div_Click(object sender, EventArgs e)
        {
            temp += this.btn_div.Text.Trim();
            this.text_display.Text = temp;
        }

        private void btn_clear_Click(object sender, EventArgs e)
        {
            this.text_display.Text = string.Empty;
            temp = string.Empty;
        }

        private void btn_left_bracket_Click(object sender, EventArgs e)
        {
            temp +=this.btn_left_bracket.Text.Trim();
            this.text_display.Text = temp;
        }

        private void btn_right_bracket_Click(object sender, EventArgs e)
        {
            temp += this.btn_right_bracket.Text.Trim();
            this.text_display.Text = temp;
        }
    }
}
